package j01set;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

public class J3for {
    public static void main(String[] args) {
        HashSet<Integer> arr = new HashSet<>();
        arr.add(1);
        arr.add(15);
        arr.add(77);
        for (Integer temp :
                arr) {
            System.out.println("temp = " + temp);
        }
        System.out.println("===");
    }
}
class J4quchong{
    public static void main(String[] args) {
        class Cat{
            String name;
            int age;

            public Cat(String name, int age) {
                this.name = name;
                this.age = age;
            }

            @Override
            public boolean equals(Object o) {
                if (this == o) return true;
                if (o == null || getClass() != o.getClass()) return false;
                Cat cat = (Cat) o;
                return age == cat.age && Objects.equals(name, cat.name);
            }

            @Override
            public int hashCode() {
                return Objects.hash(name, age);
            }

            @Override
            public String toString() {
                return "Cat{" +
                        "name='" + name + '\'' +
                        ", age=" + age +
                        '}';
            }
        }
        HashSet<Cat> arr = new HashSet<>();
        arr.add(new Cat("加菲猫",2));
        arr.add(new Cat("加菲猫2",22));
        arr.add(new Cat("加菲猫",2));
        System.out.println("arr = " + arr);
    }
}

class J4linked{
    public static void main(String[] args) {
//        LinkedHashSet<String> arr = new LinkedHashSet<>();
//        Set<String> arr = new HashSet<>();
        Set<String> arr = new LinkedHashSet<>();
        arr.add("hello");
        arr.add("word");
        arr.add("lanou");
        arr.add("huanlan");
        System.out.println("arr = " + arr);
    }
}
